<?php 
header('Access-Control-Allow-Origin:*');  //支持全域名访问，不安全，部署后需要固定限制为客户端网址
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); //支持的http 动作
header('Access-Control-Allow-Headers:x-requested-with,content-type'); 
$conn=mysqli_connect("localhost","root","","fruit");
$conn->query("set names utf_8");
$type=$_POST["type"];
switch ($type) {
  case "add":
    $name=$_POST["name"];
    $phone = $_POST["phone"];
        $phone2 = $_POST["phone2"];
        $place = $_POST["place"];
        $defaultAdd=$_POST["defaultAdd"];
        $sql="INSERT INTO address (name,phone,phone2,place,defaultAdd) VALUE ('{$name}','{$phone}','{$phone2}','{$place}','{$defaultAdd}')";
        $conn->query($sql);
        if (mysqli_affected_rows($conn)>0) {
          echo '{"bol":true}';
        }else{
            echo '{"bol":false}';
        }
    break;
  case "get":
    $sql="SELECT * FROM address";
    $ret = $conn->query($sql);

$arr = array();
while ($row = $ret->fetch_assoc()) {
    $arr[] = $row;
}
$str = json_encode($arr);
echo '{"data":'.$str.'}';
        break;
}
 ?>